Skip to main content

Find the proportion of mothers and age at first birth

The script below shows how to find the proportion of mothers and age at first birth among women aged 16 or older, who are resident in Norway as of 1/1 2023.

 // Connect to database
require no.ssb.fdb:30 as db

// Create population dataset of women 16 years or older, residing in Norway as of 1/1 2023 
create-dataset women
import db/BEFOLKNING_STATUSKODE 2023-01-01 as regstat
import db/BEFOLKNING_KJOENN as gender
import db/BEFOLKNING_FOEDSELS_AAR_MND as birthyearmonth
generate birthyear = int(birthyearmonth / 100)
generate age = 2023 - birthyear
keep if gender == '2' & age >= 16 & regstat == '1'

// Create child dataset consisting of firstborns (parity == 1)
create-dataset childdata
import db/BEFOLKNING_PARITET as parity
keep if parity == 1

import db/BEFOLKNING_MOR_FNR as motherid
import db/BEFOLKNING_FOEDSELS_AAR_MND as birthyearmonth_child
generate birthyear_child = int(birthyearmonth_child / 100)

collapse(mean) birthyear_child, by(motherid)

textblock
The child dataset now has mother as a unit and contains the average birth year for firstborns = actual birth year for firstborns (you can alternatively use the command collapse(min), and then you do not first need to select on parity == 1 since you will anyway find the time of first birth per mother). The dataset can now be merged with the women dataset
endblock

merge birthyear_child into women

textblock
Now we have the birth year for the firstborn attached for all mothers in the women dataset. Those who have missing for birthyear_child are not mothers.
endblock

use women
generate mother = !sysmiss(birthyear_child)
generate age_at_birth = birthyear_child - birthyear

textblock
The proportion of mothers among women 16 years and older residing in Norway as of 1/1 2023:
endblock

tabulate mother, freq cellpct
piechart mother

textblock
Age at first birth for all mothers, and for mothers born in the 40s, 50s, 60s, and 70s respectively
endblock

summarize age_at_birth
histogram age_at_birth, discrete

tabulate birthyear if inrange(birthyear,1970,1979), summarize(age_at_birth)
tabulate birthyear if inrange(birthyear,1960,1969), summarize(age_at_birth)
tabulate birthyear if inrange(birthyear,1950,1959), summarize(age_at_birth)
tabulate birthyear if inrange(birthyear,1940,1949), summarize(age_at_birth)